// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({env: cloud.DYNAMIC_CURRENT_ENV})
const db = cloud.database()
const dbTask = db.collection('task')

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  if(event.action == "getHomeTask"){
    var homeTaskList = await dbTask.where({
      state:0
    }).get()
    return homeTaskList['data']
  }
  if(event.action == "getMyPublishTask"){
    var myPublishTaskList = await dbTask.where({
      publisherInfo:{
        openid:event.openid
      }
    }).get()
    return myPublishTaskList['data']
  }
  if(event.action == "getMyReceiveTask"){
    var myReceiveTaskList = await dbTask.where({
      receiverInfo:{
        openid:event.openid
      }
    }).get()
    return myReceiveTaskList['data']
  }
}